package com.enumeration.demo02;

public class EnumTest {
    public static void main(String[] args) {
        System.out.println("枚举类的常用方法");
        /**
         * values() 返回枚举类中的所有枚举值 数组
         * ordinal() 枚举值的所在位置 返回 int 类型
         * valueOf() 返回枚举值
         * name() 以字符串形式返回常量名 String
         */
        Seasons[] arr = Seasons.values();
        for (Seasons seasons : arr) {
            System.out.println(seasons);
        }

        System.out.println(Seasons.SPRING.ordinal()); // 0
        System.out.println(Seasons.valueOf("AUTUMN")); // AUTUMN
        // 不存在报错 java.lang.IllegalArgumentException: No enum constant
        // System.out.println(Seasons.valueOf("RED"));
        Seasons s = Seasons.valueOf("AUTUMN");
        System.out.println(Seasons.WINTER.name());
    }
}
